# -*- coding: utf-8 -*-
"""
支持延迟初始化
这个实现采用了延迟初始化的方式,只有在首次访问单例对象时才会进行初始化。
"""
import threading


class Singleton(object):
    _instance = None
    _lock = threading.Lock()
    _initialized = False

    def __new__(cls, *args, **kwargs):
        with cls._lock:
            if cls._instance is None:
                cls._instance = super(Singleton, cls).__new__(cls)
        return cls._instance

    def __init__(self, param1, param2):
        with self._lock:
            if not self._initialized:
                self.param1 = param1
                self.param2 = param2
                self._initialized = True
